/**
 * Created by L on 2017/6/3.
 */

var url="http://47.93.233.182/";

window.onload=function () {
    $.ajax({
        url:url+"/getRecruitImg",
        type:'GET',
        dataType:'JSON',
        success:function (text) {
            lunbo(text);
        },
        error:function () {

        }
    });

    $.ajax({
        url:url+"/getRecruitInfo",
        type:'GET',
        dataType:'JSON',
        success:function (text) {
            //动态生成
            activeElement(text);
        },
        error:function () {

        }
    });

    //进一步了解点击事件
    $.ajax({
        url:url+"/getJoins",
        type:'GET',
        dataType:'JSON',
        success:function (text) {
            joinsUs(text);
        },
        error:function () {

        }
    })

};
//动态生成加入我们
function joinsUs(text) {
    $(".jianjie").html(text.data.content);
}

//动态生成
function activeElement(text) {
    var len=text.data.length;
    var arr1 = new Array();
    var arr2 = new Array();
    var arr3 = new Array();
    var arr4 = new Array();
    var index1=0;

    for(var i=0;i<len;i++){
        arr1[i] = new Array();
        arr1[i][0] = text.data[i];
        var index=1;

        for(var j=i+1;j<len;j++){
            if(text.data[i].recruit_info_department==text.data[j].recruit_info_department){
                arr1[i][index]=text.data[j];
                index++;
            }
        }
    }

    for(var b=0;b<arr1.length;b++){
       arr2[b]=arr1[b][0].recruit_info_department;
    }

    for(var d=0;d<arr2.length;d++){
        for(var e=d+1;e<arr2.length;e++){
            if(arr2[d]==arr2[e]&&arr2[d]!=undefined){
                delete arr2[e];

            }
        }
    }

    for(var m=0;m<arr2.length;m++){
        if(arr2[m]!=undefined){
            arr3[index1]=arr2[m];
            index1++;
        }
    }

    for(var z=0;z<arr3.length;z++){
        arr4[z]=new Array();
        var index2=0;
        for(var zz=0;zz<text.data.length;zz++){

            if(arr3[z]==text.data[zz].recruit_info_department){
                arr4[z][index2]=text.data[zz];
                index2++;
            }
        }
    }

    console.log(arr4);
    var content=document.getElementById("contentOfWorks");
    for(var i=0;i<arr4.length;i++){
        var wokrPosition=document.createElement("h1");
        wokrPosition.setAttribute("class","bumen");
        content.appendChild(wokrPosition);
        $(".bumen").eq(i).html(arr4[i][0].recruit_info_department);

        for(var op=0;op<arr4[i].length;op++){
            var work1=document.createElement("p");
            work1.setAttribute("class","work1");
            work1.setAttribute("id",String(i)+String(op));

            content.appendChild(work1);
            document.getElementById(String(i)+String(op)).innerHTML="【职位："+arr4[i][op].recruit_info_position+"】";

            var workIntroduce=document.createElement("p");
            workIntroduce.setAttribute("class","workIntroduce");
            workIntroduce.setAttribute("id","WI"+String(i)+String(op));
            content.appendChild(workIntroduce);

            document.getElementById("WI"+String(i)+String(op)).innerHTML=arr4[i][op].recruit_info_introduce;

            var moreInfo=document.createElement("a");
            moreInfo.setAttribute("class","moreInfo");
            moreInfo.setAttribute("id","MI"+String(i)+String(op));
            content.appendChild(moreInfo);
            document.getElementById("MI"+String(i)+String(op)).innerHTML="进一步了解>>";

            var InfoDiv=document.createElement("div");
            InfoDiv.setAttribute("class","InfoDiv");
            InfoDiv.setAttribute("id","ID"+String(i)+String(op));
            content.appendChild(InfoDiv);

            var InfoDivC=document.getElementById("ID"+String(i)+String(op));

            var workName=document.createElement("p");
            workName.setAttribute("class","workName");
            workName.setAttribute("id","WN"+String(i)+String(op));
            InfoDivC.appendChild(workName);

            document.getElementById("WN"+String(i)+String(op)).innerHTML="联系人： "+arr4[i][op].recruit_info_contactman;

            var workTel=document.createElement("p");
            workTel.setAttribute("class","workName");
            workTel.setAttribute("id","WT"+String(i)+String(op));
            InfoDivC.appendChild(workTel);

            document.getElementById("WT"+String(i)+String(op)).innerHTML="电话 ："+arr4[i][op].recruit_info_contacttel;

            var workEmail=document.createElement("p");
            workEmail.setAttribute("class","workName");
            workEmail.setAttribute("id","WE"+String(i)+String(op));
            InfoDivC.appendChild(workEmail);

            document.getElementById("WE"+String(i)+String(op)).innerHTML="邮箱 ："+arr4[i][op].recruit_info_contactemail;

            var workRequire=document.createElement("div");
            workRequire.setAttribute("class","workRequire");
            workRequire.setAttribute("id","WR"+String(i)+String(op));
            InfoDivC.appendChild(workRequire);

            document.getElementById("WR"+String(i)+String(op)).innerHTML=arr4[i][op].recruit_info_require;

        }

    }


    moreEvent();
}


//进一步了解点击事件
function moreEvent(){

    $(".moreInfo").click(function () {
        var len=$('.moreInfo').index(this);
        $(".InfoDiv").eq(len).slideToggle();
    })
}


//轮播器
function lunbo(text) {

    var ol=document.getElementsByClassName("carousel-indicators")[0];
    var div=document.getElementsByClassName("carousel-inner")[0];
    for(var i=0;i<text.data.length;i++){
        var li=document.createElement("li");
        li.setAttribute("data-target","#carousel-example-generic");
        li.setAttribute("data-slide-to",i);
        ol.appendChild(li);

        var div2=document.createElement("div");
        div2.setAttribute("class","item");
        div.appendChild(div2);
        $(".item").eq(i).css({
            "background":"url("+url+text.data[i].aboutcompany_image+")",
            "background-size":"cover",
            "width":"100%"
        })
    }

    $(".carousel-indicators li").eq(0).attr("class","active");
    $(".carousel-inner div").eq(0).attr("class","item active");

}



